Home | | Latest | About | Random
# Getting VS Code and GCC compiler for Windows.
According to the VS Code website [https://code.visualstudio.com/docs/cpp/config-mingw](https://code.visualstudio.com/docs/cpp/config-mingw), this is the recommended step to obtain VS Code, configuring it, and obtaining the GCC C++ compiler.
## Obtain VS Code and a C/C++ Extension.
Step 1. Download and install VS Code [here](https://code.visualstudio.com/download?_exp_download=fb315fc982),
Step 2. Install a C/C++ extension language support for VS Code [here](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools).
- This extension adds features to VS Code such as syntax highlighting to assist us in writing C/C++ programs.
## Obtain the GCC compiler via MSYS2.
Step 3. Download and install [MSYS2](https://www.msys2.org/). This is a Unix-like development platform that we will use to obtain the GCC C++ compiler.
- Note down the folder and path where MSYS2 is installed to.
- When it has done installing, RUN MYSY2 now, this will open up the MSYS2 terminal.
Step 4. In the MSYS2 terminal copy and paste the following command, and hit `enter` to run it:
```MSYS2
pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
```
To copy: Select above line and hit `ctrl` + `c`, and to paste in the terminal you can right click on it and select paste. Or, you can just type it in verbatim.
Step 5. Accept all packages by hitting `enter`.
Step 6. Proceed with installation by hitting `Y` and `enter`. It will then begin to retrieve packages and install them. This will take a short while, so be patient. When it is down it will return to the prompt, which we can exit out the terminal if we like.
## Add the GCC path to Windows Environment Variables.
Step 7. Now we need to tell Windows how to run the GCC compiler from anywhere, by telling Windows where GCC itself is. We do this by adding to the PATH variable of Windows.
- Hit `Win` key, or the Windows icon, and type "path" and see if it suggests "Edit the system environment variables." Select it.
- Click on the button "Environment Variables".
- Select in the list "Path", and hit "Edit..." button.
- Hit "new", and type in `C:\msys64\ucrt64\bin` (assuming you used the default installation path of MSYS2)
- Hit "Ok" to confirm our modification. Hit "Ok" again a few times.
## Verify our installation and path configuration.
Step 8. Let us check if it is install correctly.
- Hit `win` +`r` and type `cmd`, and hit `enter`. This brings up the Windows Command Prompt terminal.
- Type `g++ --version` and hit `enter`. If it gives version information, then that means you did it!
## Write our first C++ Program using VS Code.
You should use folders to organize the C++ code you write. Typically it's good to put the same code of the same project in the same folder. So in VS Code, go to "File" and select "Open Folder". Choose (or create one) a folder that you will write and save your first C++ program.
Select "Trust Author", as you are the author of this folder.
Select "File", then "New Text File" (or do `ctrl` + `n`). A C++ program is nothing but a text file!
Type in (and try to do it by hand) the following piece of code.
```cpp
int main(){
return 0;
}
```
Save it as `main.cpp`.
As you do so, it might prompt you to install a C/C++ Extension pack. Install it.
On the top of text editing area, there is a triangle button with a little bug next to it. This is the debug button, you can also click the drop down next to it and select "Run C/C++ File"
If it prompts you to install Python, or needs to search path for certain cmake file, agree to all.
This could take a while if it is the first time. But it it runs it should show in the terminal below that nothing wrong happens!
Try modifying your code to this "Hello World"
```cpp
#include
using namespace std;
int main(){
cout << "Hello, World!";
return 0;
}
```
Save, and hit the triangle button. Play around with it!
## Getting Windows PowerShell 7
In Command prompt, type and run:
```cmd
winget install Microsoft.PowerShell
```